from __future__ import unicode_literals

from django.contrib.auth.models import User
from django.db import models
from django.db.models import ForeignKey


class Sort(models.Model):
    classifies = models.CharField(max_length=10)

    def __unicode__(self):
        return '%s' % (self.classifies)


class Article(models.Model):
    title = models.CharField(max_length=30)
    cover_img = models.ImageField(upload_to='article/')
    content = models.TextField()
    pub_time = models.DateTimeField(auto_now_add=True)
    last_edit_time = models.DateTimeField(auto_now=True)
    author = ForeignKey(User, related_name='owner_articles')
    last_editor = ForeignKey(User, related_name='last_editor_articles')
    sort = ForeignKey(Sort, related_name='sort_article')

    def __unicode__(self):
        return '%s %s %s %s %s %s %s %s' % (
            self.title, self.cover_img, self.content, self.pub_time, self.last_edit_time, self.author, self.last_editor,
            self.sort
        )
